//
//  BiCustomerInfoViewController.m
//  TrunkIndustryManageSystem
//
//  Created by WT_lyy on 15/4/22.
//  Copyright (c) 2015年 李璐西. All rights reserved.
//
#define BOTTOM_BUTTON_HEIGHT 40
#import "CLLocation+YCLocation.h"

#import "BiCustomerInfoViewController.h"
#import "BiSaleExecuteCheckViewController.h"
#import <CoreLocation/CoreLocation.h>
#import "BiCustomerInfo.h"
#import <MAMapKit/MAMapKit.h>
#import <AMapSearchKit/AMapSearchAPI.h>
#import <AssetsLibrary/AssetsLibrary.h>
@interface BiCustomerInfoViewController ()<UITableViewDataSource,UITableViewDelegate,UIImagePickerControllerDelegate, UINavigationControllerDelegate,CLLocationManagerDelegate,AMapSearchDelegate>{

    IBOutlet UIView *_headView;
    
    UITableView * _tableView;
    
    NSInteger isOwner; //  1是车主，0不是
    
    NSInteger imageType; // 1,kehu  2客户与车 3就餐
    
    UIImageView * _imView;
    
    NSString * _collectAddres;
    
    CLLocationManager* locationMgr;
    
    CLLocationCoordinate2D  nowcoordinate;
    
    
    float lineDis;
    
    float distance;
}

@property (weak, nonatomic) IBOutlet UITextField *textfCustomer;

@property (weak, nonatomic) IBOutlet UITextField *textfTel;
@property (weak, nonatomic) IBOutlet UILabel *labCollect;
@property (weak, nonatomic) IBOutlet UILabel *labDistance;
@property (weak, nonatomic) IBOutlet UILabel *labTrackDis;

@property (weak, nonatomic) IBOutlet UIButton *btnIsowner;
@property (weak, nonatomic) IBOutlet UIButton *btnNoowner;

@property (nonatomic,strong) UIImage * cusTimage;
@property (nonatomic,strong) UIImage * cusTcarimage;
@property (nonatomic,strong) UIImage * cusTeatimage;

@property (nonatomic, strong) AMapSearchAPI *search;
@end


@implementation BiCustomerInfoViewController

- (void)viewDidLoad {
    
    isOwner = 0;
    
    [super viewDidLoad];
   
    [self setNavBackBtn];
    
    [self setNavBarWithHidden:NO];
    
    [self setNavBarTitle:@"客户信息"];

    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, [self viewTop], MAIN_SCREEN_WIDTH, MAIN_SCREEN_HEIGHT-[self viewTop]-BOTTOM_BUTTON_HEIGHT)];
    
    _tableView.delegate = self;
    
    _tableView.dataSource = self;
    
    [self.view addSubview:_tableView];
    
    _tableView.rowHeight = 144;
    
    _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    _tableView.tableHeaderView = _headView;
    
    UIButton * btnSaeve = GET_BUTTON(CGRectMake(0, MAIN_SCREEN_HEIGHT-BOTTOM_BUTTON_HEIGHT, MAIN_SCREEN_WIDTH, BOTTOM_BUTTON_HEIGHT), 17, NO, [UIColor whiteColor]);
    
    [self.view addSubview:btnSaeve];
    
    [btnSaeve setTitle:@"保存" forState:UIControlStateNormal];
    
    btnSaeve.backgroundColor = UIColorFromRGB(BLUE_COLOR_VALUE);
    
    [btnSaeve addTarget:self action:@selector(btnSaveClick:) forControlEvents:UIControlEventTouchUpInside];
    
    self.labCollect.text = [BiUserEntity sharedInstance].name;
    
    _textfCustomer.frame = CGRectMake(45, 10, 110, 20);
    
    _textfTel.frame = CGRectMake(45, 40, 110, 20);
    
    [self dataFill];
    
    UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapClick)];
    
    [self.view addGestureRecognizer:tap];
}

- (void)tapClick{

    [_textfCustomer resignFirstResponder];
    [_textfTel resignFirstResponder];
}

- (void)dataFill{
    
    [self.btnIsowner setImage:LOAD_IMAGE_WITH_CACHE(@"CarSale/buton.png") forState:UIControlStateNormal];
    
    [self.btnNoowner setImage:LOAD_IMAGE_WITH_CACHE(@"CarSale/butono.png") forState:UIControlStateNormal];

    if (_cusEntity) {
        
        _textfCustomer.text =  _cusEntity.customerName;
        
        _textfTel.text = _cusEntity.customerPhone;
        
        self.labTrackDis.text = [NSString stringWithFormat:@"%0.2f KM",[_cusEntity.distance floatValue]];
        
        self.labDistance.text = [NSString stringWithFormat:@"%0.2f KM",[_cusEntity.lineDistance floatValue]];
        
        if (![_cusEntity.isOwer boolValue]) {
            [self.btnIsowner setImage:LOAD_IMAGE_WITH_CACHE(@"CarSale/buton.png") forState:UIControlStateNormal];
            [self.btnNoowner setImage:LOAD_IMAGE_WITH_CACHE(@"CarSale/butono.png") forState:UIControlStateNormal];
        }else{
            [self.btnNoowner setImage:LOAD_IMAGE_WITH_CACHE(@"CarSale/buton.png") forState:UIControlStateNormal];
            [self.btnIsowner setImage:LOAD_IMAGE_WITH_CACHE(@"CarSale/butono.png") forState:UIControlStateNormal];
        }

        
    }
}

#pragma -mark  Button Action
- (void)btnSaveClick:(UIButton *)sender{
    
    if ([BiUtil isBlankString:_textfCustomer.text]) {
        
        [self showMessage:@"请输入客户姓名"];
        return;
    }
    if (![GT_Tool Isphonenumber:_textfTel.text]) {
        
        [self showMessage:@"请输入正确的电话号码"];
        return;
    }
    
    
    for (BiCustomerInfo * info in self.phoneJudgeArr) {
        
        if (info.customerPhone.hash == _textfTel.text.hash) {
            
            [self showMessage:@"请输入正确的电话号码"];
            return;
        }
    }
    
    NSString *  collectAddres = !_collectAddres?self.cusEntity.collectAddress:_collectAddres;
    
    collectAddres = collectAddres?collectAddres:@"";
    
    NSDictionary * tempDic = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithDouble:nowcoordinate.longitude],@"longitude",
                             [NSNumber numberWithDouble:nowcoordinate.latitude],@"latitude",
                              [NSString stringWithFormat:@"%0.2f",lineDis],@"lineDistance",
                              [NSString stringWithFormat:@"%0.2f",distance],@"distance",
                              [BiUtil stringFromFomate:[NSDate date] formate:@"yyyy-MM-dd hh:mm:ss"],@"collectTime",
                              [NSString stringWithFormat:@"%d",(int)isOwner],@"isOwer",
                              [BiUserEntity sharedInstance].userid,@"messageColletPersonId",
                              _textfTel.text,@"customerPhone",
                              _textfCustomer.text,@"customerName",
                              self.Centity.e_id,@"sellId",
                              @"0",@"id",
                              collectAddres,@"collectAddress",nil];
    
    
    NSArray * paraArr = [NSArray arrayWithObject:tempDic];
    

    [[BiNetEngine shareInstance] requestSaleAddCustomerInfo:self paraArr:paraArr];
    
//     NSString * filename = [NSString stringWithFormat:@"%u",arc4random()];
//    if (self.cusTimage) {
//        
//        NSDictionary * paraDicIm1 = [NSDictionary dictionaryWithObjectsAndKeys:self.Centity.e_id,@"id",@"1",@"imgType",filename,@"fileName", nil];
//        
//         [[BiNetEngine shareInstance] requestSaleCuntomerImageCusT:self withImge:self.cusTimage paraDic:paraDicIm1];
//    }
//    
//    if (self.cusTcarimage) {
//        
//        NSDictionary * paraDicIm2 = [NSDictionary dictionaryWithObjectsAndKeys:self.Centity.e_id,@"id",@"2",@"imgType",filename,@"fileName", nil];
//        
//        [[BiNetEngine shareInstance] requestSaleCuntomerImageCusTCar:self withImge:self.cusTcarimage paraDic:paraDicIm2];
//    }
//    if (self.cusTeatimage) {
//        NSDictionary * paraDicIm3 = [NSDictionary dictionaryWithObjectsAndKeys:self.Centity.e_id,@"id",@"3",@"imgType",filename,@"fileName", nil];
//        
//        [[BiNetEngine shareInstance] requestSaleCuntomerImageCusTEat:self withImge:self.cusTcarimage paraDic:paraDicIm3];
//    }
//   
    
  //  [self asyshowHUDView:WAITING CurrentView:self];
    
}

- (void)btnImageClick:(UIButton *)sender{
    
    if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
    {
        UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:@"相机功能不可用" message:nil delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil];
        [alertView show];
        return;
    }
    
    UIImagePickerController * picker = [[UIImagePickerController alloc]init];
    picker.delegate = self;
    picker.allowsEditing = YES;
    picker.sourceType = UIImagePickerControllerSourceTypeCamera;
    [self presentViewController:picker animated:YES completion:nil];
    
    imageType = sender.tag + 1;
    
    
    
    if (!_cusEntity) {
        
        if (!locationMgr) {
            locationMgr = [[CLLocationManager alloc] init];
            
            locationMgr.delegate = self;
            locationMgr.desiredAccuracy = kCLLocationAccuracyNearestTenMeters;
            locationMgr.distanceFilter = FILTER_DISTANCE; //位置更新最小距离
            if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0){
                [locationMgr requestAlwaysAuthorization];
                [locationMgr requestWhenInUseAuthorization];
            }
            
            if ([CLLocationManager locationServicesEnabled]) {
                // 启动位置更新
                // 开启位置更新需要与服务器进行轮询所以会比较耗电，在不需要时用stopUpdatingLocation方法关闭;
                [locationMgr startUpdatingLocation];
            }
            else {
                [self showMessage:@"请开启定位功能！"];
            }
        }
    }
    
}

- (IBAction)btnIsOwner:(UIButton *)sender {
    
    isOwner = sender.tag;
    
    if (0 == sender.tag) {
        [self.btnIsowner setImage:LOAD_IMAGE_WITH_CACHE(@"CarSale/buton.png") forState:UIControlStateNormal];
        [self.btnNoowner setImage:LOAD_IMAGE_WITH_CACHE(@"CarSale/butono.png") forState:UIControlStateNormal];
    }else{
        [self.btnNoowner setImage:LOAD_IMAGE_WITH_CACHE(@"CarSale/buton.png") forState:UIControlStateNormal];
        [self.btnIsowner setImage:LOAD_IMAGE_WITH_CACHE(@"CarSale/butono.png") forState:UIControlStateNormal];
    }
}

#pragma -mark  UITextFieldDelegate
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    
    return YES;
}


#pragma -mark UitabeViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
}

#pragma -mark UitabeViewDatasource

- (NSInteger )tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return 3;
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString * myIndentifier = @"CustomerCell";
    
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:myIndentifier];
    
    if (!cell)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:myIndentifier];
        
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
        UILabel * labtitle = GET_LABEL(CGRectMake(0, 0, MAIN_SCREEN_WIDTH, 32), 14, NO, [UIColor blackColor], NSTextAlignmentLeft);
        
        labtitle.backgroundColor = UIColorFromRGB(0xf6f7f9);
        
        [cell addSubview:labtitle];
        
        labtitle.tag = 1111;
        
        UIImageView * imView = [[UIImageView alloc]initWithFrame:CGRectMake(10, 40, 100, 100)];
        
        [cell addSubview:imView];
        
        imView.image = LOAD_IMAGE_WITHOUT_CACHE(@"CarSale/default");
        
        //imView.backgroundColor = [UIColor lightGrayColor];
        
        imView.tag = 1100;
        
        UIButton * btnUpimage = GET_BUTTON(CGRectMake(240, 100, 70, 30), 14, NO, [UIColor whiteColor]);
        
        [btnUpimage setTitle:@"照片上传" forState:UIControlStateNormal];
        
        btnUpimage.backgroundColor = UIColorFromRGB(ORANGE_COLOR_VALUE);
        
        btnUpimage.tag = indexPath.row;
        
        [cell addSubview:btnUpimage];
        
        [btnUpimage addTarget:self action:@selector(btnImageClick:) forControlEvents:UIControlEventTouchUpInside];
        
    }
    
    
    UILabel * labtitl = (UILabel *)[cell viewWithTag:1111];
    
    if (0 == indexPath.row) {
        
        labtitl.text = @"  客户合影:";
    }else if (1 == indexPath.row){
        
        labtitl.text = @"  客户与车的合影:";
    }else if (2 == indexPath.row){
        
        labtitl.text = @"  就餐合影:";
    }
    
    UIImageView * imageVie = (UIImageView *)[cell viewWithTag:1100];
    
    if (0 == indexPath.row ) {
        if (self.cusEntity.imageCust) {
            imageVie.image = self.cusEntity.imageCust;
        }else if (self.cusEntity.visitorCustomerPhoto.length != 0){
        
            [self reloadImage:self.cusEntity.visitorCustomerPhoto withIm:imageVie info:self.cusEntity Tag:indexPath.row];
        }
        
    } else  if (1 == indexPath.row ) {
        if (self.cusEntity.imageCustCar) {
            imageVie.image = self.cusEntity.imageCustCar;
        }else if (self.cusEntity.customerCarphoto.length != 0){
            
            [self reloadImage:self.cusEntity.customerCarphoto withIm:imageVie info:self.cusEntity Tag:indexPath.row];
        }
        
    }else  if (2 == indexPath.row ) {
        if (self.cusEntity.imageCustEat) {
            imageVie.image = self.cusEntity.imageCustEat;
        }else if (self.cusEntity.restaurantPhoto.length != 0){
            
            [self reloadImage:self.cusEntity.restaurantPhoto withIm:imageVie info:self.cusEntity Tag:indexPath.row];
        }
        
    }
    
    return cell;
}


-(void)reloadImage:(NSString *)url withIm:(UIImageView *)imview info:(BiCustomerInfo *)info Tag:(NSInteger )tag{
    if (!url||[url isEqual:[NSNull null]] || [url isEqualToString:@"<null>"] || url.length==0) {
        [imview setImage:nil];
        return;
    }
    NSString *url_ =[NSString stringWithFormat:@"%@%@",SERVICE_URL_FORMAL,url];
    
    NSString *localPath = [NSString stringWithFormat:@"%@/%@",[BiUtil tempImageFilePath],[url lastPathComponent]];
    if ([[NSFileManager defaultManager] fileExistsAtPath:localPath]) {
        [imview setImage:[UIImage imageWithContentsOfFile:localPath]];
    }else {
        NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url_]];
        [request setHTTPMethod:@"GET"];
        NSOperationQueue *queue = [NSOperationQueue mainQueue];
        [NSURLConnection sendAsynchronousRequest:request
                                           queue:queue
                               completionHandler:^(NSURLResponse *response,
                                                   NSData *data,
                                                   NSError *error){
                                   if (data) {
                                       dispatch_async(dispatch_get_main_queue(), ^{
                                           UIImage *downLoadImage = [UIImage imageWithData:data];
                                           if (downLoadImage.size.width >200 ) {
                                               downLoadImage  =[BiUtil scaleToSize:downLoadImage size:CGSizeMake(200,  downLoadImage.size.height*200/downLoadImage.size.width)];
                                           }
                                           [imview setImage:downLoadImage];
                                           [imview setNeedsDisplay];
                                           [imview setNeedsLayout];
                                           if (0 == tag) {
                                               info.imageCust = downLoadImage;
                                           }else if (1 == tag){
                                               info.imageCustCar = downLoadImage;
                                           }else if (1 == tag){
                                               info.imageCustEat = downLoadImage;
                                           }
                                           dispatch_queue_t bgque = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
                                           dispatch_async(bgque, ^{[data writeToFile:localPath atomically:YES];});
                                           
                                       });
                                   }
                                   
                               }];
    }
}



#pragma mark UIImagePickerControllerDelegate
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
{
    [picker dismissViewControllerAnimated:YES completion:nil];
    image = [BiUtil scaleToSize:image size:CGSizeMake(200, 200)];
    
    if (1 == imageType) {
        self.cusTimage = image;
        
    }else if (2 == imageType){
        self.cusTcarimage = image;
    }else if (3 == imageType){
        self.cusTeatimage = image;
    }
    NSIndexPath * indexPath = [NSIndexPath indexPathForRow:imageType-1 inSection:0];
    
    UITableViewCell * cell = [_tableView cellForRowAtIndexPath:indexPath];
    
    UIImageView * imv = (UIImageView *)[cell viewWithTag:1100];
    
    imv.image = image;
    
    
    if(picker.sourceType == UIImagePickerControllerSourceTypePhotoLibrary){
        //UIImage *image= [info objectForKey:UIImagePickerControllerOriginalImage];
        
        NSURL *assetURL = [editingInfo objectForKey:UIImagePickerControllerReferenceURL];
        ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
        [library assetForURL:assetURL
                 resultBlock:^(ALAsset *asset) {
                     NSDictionary* imageMetadata = [[NSMutableDictionary alloc] initWithDictionary:asset.defaultRepresentation.metadata];
                   //  NSDictionary *GPSDict=[imageMetadata objectForKey:kCGImagePropertyGPSDictionary];
                   //  NSLog(@"%@",GPSDict);
                     NSLog(@"%@",imageMetadata);
                     /* GPSDict 里面即是照片的GPS信息,具体可以输出看看*/
                 }
                failureBlock:^(NSError *error) {
                }];
    }
    
    
}


- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
    [picker dismissViewControllerAnimated:YES completion:nil];
}


#pragma mark - AMapSearchDelegate

/* 逆地理编码回调. */

-(void)onReGeocodeSearchDone:(AMapReGeocodeSearchRequest *)request response:(AMapReGeocodeSearchResponse *)response{
    
    
    //NSLog(@"%@",response);
    
    NSString * addrestr =  response.regeocode.formattedAddress;
    
    addrestr = [addrestr substringFromIndex:3];
    
    _collectAddres = addrestr;
    
    
}

#pragma mark - CLLocationManagerDelegate
//地理位置发生改变时触发
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
    
    nowcoordinate = [newLocation locationMarsFromEarth].coordinate;
    
    self.search = [[AMapSearchAPI alloc] initWithSearchKey:[MAMapServices sharedServices].apiKey Delegate:self];
    
    [self searchReGeocodeWithCoordinate:nowcoordinate];
    
    
    NSString * sqlStr = [NSString stringWithFormat:@"select * from table_track where systemNum=%@ order by creatdate asc",self.Centity.e_id];
    
    NSArray * locArr = [[DBManager sharedInstance] querryTable:sqlStr];
    
    NSDictionary * locDic = [locArr firstObject];
    
    //此处断点提示 距离计算 修改为火星坐标
    CLLocation *dist = [[CLLocation alloc] initWithLatitude:[locDic[@"latitude"] doubleValue]  longitude:[locDic[@"longitude"] doubleValue]];
    
    CLLocation *start = [[CLLocation alloc] initWithLatitude:nowcoordinate.latitude longitude:nowcoordinate.longitude];
    
    CLLocationDistance metersUF = [start distanceFromLocation:dist];
    
    float kiloMter = metersUF/1000;
    
    float kiloTrack = 0;
    
    if (locArr.count > 2) {
       kiloTrack = (locArr.count-2)*FILTER_DISTANCE/1000;
    }
    
    lineDis = kiloMter;
    
    distance = kiloTrack;
    
    self.labTrackDis.text = [NSString stringWithFormat:@"%0.2f KM",kiloTrack];
    
    self.labDistance.text = [NSString stringWithFormat:@"%0.2f KM",kiloMter];
    
    [manager stopUpdatingLocation];
    
    manager.delegate = nil;
}

- (void)searchReGeocodeWithCoordinate:(CLLocationCoordinate2D)coordinate
{
    AMapReGeocodeSearchRequest *regeo = [[AMapReGeocodeSearchRequest alloc] init];
    
    regeo.location = [AMapGeoPoint locationWithLatitude:coordinate.latitude longitude:coordinate.longitude];
    regeo.requireExtension = YES;
    
    [self.search AMapReGoecodeSearch:regeo];
    
}

// 定位失误时触发
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
    NSLog(@"error:%@",error);
}



#pragma -mark Net Delegate
- (void)onNetEngineResponse:(int)tag entity:(id)entity userInfo:(NSDictionary *)userInfo
{
    
    [self removeHUDView:self];
    
    NSDictionary * dict = (NSDictionary *)entity;
    
    
    if ([dict[@"response_status"] integerValue] != 200) {
        
        return;
        
    }
    
    switch (tag) {
        case NET_GET_XINGXIAO_CUSTOER_UPIMAGE1:
            NSLog(@"NET_GET_XINGXIAO_CUSTOER_UPIMAGE1");
            break;
        case NET_GET_XINGXIAO_CUSTOER_UPIMAGE2:
            NSLog(@"NET_GET_XINGXIAO_CUSTOER_UPIMAGE2");
            break;
        case NET_GET_XINGXIAO_CUSTOER_UPIMAGE3:
            NSLog(@"NET_GET_XINGXIAO_CUSTOER_UPIMAGE3");
            break;
        case NET_GET_XINGXIAO_ADDCUSTOMER_INFO:
        {
            
            NSString * ID = dict[@"data"][@"id"];
            
            NSString * filename = [NSString stringWithFormat:@"%u",arc4random()];
            if (self.cusTimage) {
                
                NSDictionary * paraDicIm1 = [NSDictionary dictionaryWithObjectsAndKeys:ID,@"id",@"1",@"imgType",filename,@"fileName", nil];
                
                [[BiNetEngine shareInstance] requestSaleCuntomerImageCusT:self withImge:self.cusTimage paraDic:paraDicIm1];
            }
            
            if (self.cusTcarimage) {
                
                NSDictionary * paraDicIm2 = [NSDictionary dictionaryWithObjectsAndKeys:self.Centity.e_id,@"id",@"2",@"imgType",filename,@"fileName", nil];
                
                [[BiNetEngine shareInstance] requestSaleCuntomerImageCusTCar:self withImge:self.cusTcarimage paraDic:paraDicIm2];
            }
            if (self.cusTeatimage) {
                NSDictionary * paraDicIm3 = [NSDictionary dictionaryWithObjectsAndKeys:self.Centity.e_id,@"id",@"3",@"imgType",filename,@"fileName", nil];
                
                [[BiNetEngine shareInstance] requestSaleCuntomerImageCusTEat:self withImge:self.cusTcarimage paraDic:paraDicIm3];
            }
            

            
            
            
            
            for (UIViewController * vCtrl in self.navigationController.viewControllers) {
                
                if ([vCtrl isKindOfClass:[BiSaleExecuteCheckViewController class]]) {
                    
                    BiSaleExecuteCheckViewController * exevCtrl = (BiSaleExecuteCheckViewController *)vCtrl;
                    
                    
                    BiCustomerInfo * info = nil;
                    
                    if (_cusEntity) {
                        
                        info = _cusEntity;
                    }else{
                    
                        info = [[BiCustomerInfo alloc] init];
                    }
                    
                    info.collectAddress = _collectAddres;
                    
                    info.customerName = _textfCustomer.text;
                    
                    info.customerPhone = _textfTel.text;
                    
                    info.collectTime = [BiUtil stringFromFomate:[NSDate date] formate:@"yyyy-MM-dd hh:ss"];
                    
                    if (self.cusTimage) {
                        info.imageCust = self.cusTimage;
                    }if (self.cusTcarimage) {
                        info.imageCustCar = self.cusTcarimage;
                    }if (self.cusTeatimage) {
                        info.imageCustEat = self.cusTeatimage;
                    }
                    if (!_cusEntity) {
                        
                        [exevCtrl.customerInfoList addObject:info];
                    }
                    
                    break;
                }
            }
            
            [self.navigationController popViewControllerAnimated:YES];
        }
            break;
            
        default:
            break;
    }
    
    
    
}
- (void)onNetEngineResponseFail:(int)tag entity:(id)entity userInfo:(NSDictionary *)userInfo
{
    [self removeHUDView:self];
    
}



@end
